Ideas for comparing 2 tables from 2 different modules...

Hi all,

I have a bit of a tricky task to do. I want to compare 2 tables (from different modules) and detect any changes in the cells (basic string comparison). The tables are identical (i.e. same number of rows and cells). When a change is detected a link from the object will be made to both the changed cells. I have an idea on how to achieve this and I am thinking of using a 2 dimensional array or something similar to mimick the tables. Or does anyone know of an easier way to compare 2 tables, cell by cell?

Thanks.
gpolley - Fri Jul 03 03:51:23 EDT 2009

Re: Ideas for comparing 2 tables from 2 different modules...
Peter_Albert - Fri Jul 03 04:38:29 EDT 2009

Below is a quick hack for the problem using skip lists. It only works if the tables are identical in size.

You have to add the two module's names in the script, select cells in both tables and run the script. It will only print the string comparison results, if you want to create links you have to add the appropriate code.

Peter
 

// Quick hack for comparing two tables
/*
Open the two modules, select cells in the two tables and run the script
*/
 
string modName_1 = "" // Add module name here
string modName_2 = "" // Add module name here
 
Module mod_1 = null
Module mod_2 = null
Object currObj_1, currObj_2
Object tableObj_1 = null
Object tableObj_2 = null
Object rowObj, cellObj_1, cellObj_2
Skip sList_1 = create
Skip sList_2 = create
int nKey
int nCells_1, nCells_2
// Get handle for the two modules
if (exists module modName_1 && exists module modName_2)
{ // Modules exist
  if (open module modName_1){mod_1 = module item modName_1}
  if (open module modName_2){mod_2 = module item modName_2}
} // Modules exist
if (null mod_1 || null mod_2){print "One of the modules is not open."; halt}
// Get current objects
currObj_1 = current(mod_1)
currObj_2 = current(mod_2)
if (cell currObj_1){tableObj_1 = getTable(currObj_1)}
if (cell currObj_2){tableObj_2 = getTable(currObj_2)}
if (null tableObj_1 || null tableObj_2){print "No cell selected in one of the modules"}
else
{ // Two cells selected
  // Store cell objects in Skip lists
  nKey = 0
  for rowObj in tableObj_1 do{for cellObj_1 in rowObj do{put(sList_1, nKey++, cellObj_1)}}
  nCells_1 = nKey
  nKey = 0
  for rowObj in tableObj_2 do{for cellObj_2 in rowObj do{put(sList_2, nKey++, cellObj_2)}}
  nCells_2 = nKey
  if (nCells_1 != nCells_2){print "Different table sizes!\n"}  
  for cellObj_1 in sList_1 do
  { // Loop through first table's cell objects
    print (name module cellObj_1) " #" cellObj_1."Absolute Number" " "
    nKey = (int key sList_1)
    if (!find(sList_2, nKey, cellObj_2)){print "No matching cell found\n"}
    else
    { // Matching cell found in second table
      print (name module cellObj_2) " #" cellObj_2."Absolute Number" ": "
      if (cellObj_1."Object Text" "" != cellObj_2."Object Text" "")
      { // Cells' Object Text differs
        print "Cells differ\n"
        // Create the desired links here
      } // Cells' Object Text differs
      else
      { // Cells' Object Text are identical
        print "Cells are identical\n"
      } // Cells' Object Text are identical
    } // Matching cell found in second table
  } // Loop through first table's cell objects
} // Two cells selected
delete sList_1
delete sList_2

Re: Ideas for comparing 2 tables from 2 different modules...
mgomes - Fri Jul 03 05:04:54 EDT 2009

I made this without testing....and perhaps is not very efficient. It is a start.
Object objA //object for table in module A
Object objB //object for table in module B

Object roModuleA //row
Object coModuleA //cell
Object roModuleB //row
Object coModuleB //cell

int iNumRowToCompairA = 0
int iNumColumnToCompairA = 0
int iNumRowToCompairB = 0
int iNumColumnToCompairB = 0

for roModuleA in table(objA) do
{
++iNumColumnToCompairA
iNumColumnToCompairB = 0
for roModuleB in table(objB) do
{
++iNumColumnToCompairB
if ( iNumColumnToCompairA != iNumColumnToCompairB ) continue

for coModuleA in row(roModuleA) do
{
++iNumRowToCompairA
iNumRowToCompairB = 0
for coModuleB in row(roModuleB) do
{
++iNumRowToCompairB
if ( iNumRowToCompairA != iNumRowToCompairB ) continue

if ( coModuleA."Object Text" "" == coModuleB."Object Text" "" )
print coModuleA."Object Text" " found\n"
}
}
}
}

Re: Ideas for comparing 2 tables from 2 different modules...
gpolley - Fri Jul 03 07:14:23 EDT 2009

Peter_Albert - Fri Jul 03 04:38:29 EDT 2009

Below is a quick hack for the problem using skip lists. It only works if the tables are identical in size.

You have to add the two module's names in the script, select cells in both tables and run the script. It will only print the string comparison results, if you want to create links you have to add the appropriate code.

Peter
 

// Quick hack for comparing two tables
/*
Open the two modules, select cells in the two tables and run the script
*/
 
string modName_1 = "" // Add module name here
string modName_2 = "" // Add module name here
 
Module mod_1 = null
Module mod_2 = null
Object currObj_1, currObj_2
Object tableObj_1 = null
Object tableObj_2 = null
Object rowObj, cellObj_1, cellObj_2
Skip sList_1 = create
Skip sList_2 = create
int nKey
int nCells_1, nCells_2
// Get handle for the two modules
if (exists module modName_1 && exists module modName_2)
{ // Modules exist
  if (open module modName_1){mod_1 = module item modName_1}
  if (open module modName_2){mod_2 = module item modName_2}
} // Modules exist
if (null mod_1 || null mod_2){print "One of the modules is not open."; halt}
// Get current objects
currObj_1 = current(mod_1)
currObj_2 = current(mod_2)
if (cell currObj_1){tableObj_1 = getTable(currObj_1)}
if (cell currObj_2){tableObj_2 = getTable(currObj_2)}
if (null tableObj_1 || null tableObj_2){print "No cell selected in one of the modules"}
else
{ // Two cells selected
  // Store cell objects in Skip lists
  nKey = 0
  for rowObj in tableObj_1 do{for cellObj_1 in rowObj do{put(sList_1, nKey++, cellObj_1)}}
  nCells_1 = nKey
  nKey = 0
  for rowObj in tableObj_2 do{for cellObj_2 in rowObj do{put(sList_2, nKey++, cellObj_2)}}
  nCells_2 = nKey
  if (nCells_1 != nCells_2){print "Different table sizes!\n"}  
  for cellObj_1 in sList_1 do
  { // Loop through first table's cell objects
    print (name module cellObj_1) " #" cellObj_1."Absolute Number" " "
    nKey = (int key sList_1)
    if (!find(sList_2, nKey, cellObj_2)){print "No matching cell found\n"}
    else
    { // Matching cell found in second table
      print (name module cellObj_2) " #" cellObj_2."Absolute Number" ": "
      if (cellObj_1."Object Text" "" != cellObj_2."Object Text" "")
      { // Cells' Object Text differs
        print "Cells differ\n"
        // Create the desired links here
      } // Cells' Object Text differs
      else
      { // Cells' Object Text are identical
        print "Cells are identical\n"
      } // Cells' Object Text are identical
    } // Matching cell found in second table
  } // Loop through first table's cell objects
} // Two cells selected
delete sList_1
delete sList_2

Thanks Peter. That could actually work for me. The only problem is that I have hundreds of tables to compare so selecting all the cells of the table is a no go. I'm sure it would be possible to adapt to not include this.

Re: Ideas for comparing 2 tables from 2 different modules...
Peter_Albert - Fri Jul 03 07:25:40 EDT 2009

gpolley - Fri Jul 03 07:14:23 EDT 2009
Thanks Peter. That could actually work for me. The only problem is that I have hundreds of tables to compare so selecting all the cells of the table is a no go. I'm sure it would be possible to adapt to not include this.

Sure.

First, you don't have to select all cells in all tables but rather one cell in each table. But still for hundreds of tables this is not feasible.

You can easily modify the script to a routine accepting two table header objects as input variables. Your task then is to identify the respective table header objects. The solution for this depends on your actual situation, i.e. are the tables in the same module or in different modules, are they in the same order or in different order, etc ...?

Peter

Re: Ideas for comparing 2 tables from 2 different modules...
gpolley - Fri Jul 03 10:29:47 EDT 2009

Peter_Albert - Fri Jul 03 07:25:40 EDT 2009
Sure.

First, you don't have to select all cells in all tables but rather one cell in each table. But still for hundreds of tables this is not feasible.

You can easily modify the script to a routine accepting two table header objects as input variables. Your task then is to identify the respective table header objects. The solution for this depends on your actual situation, i.e. are the tables in the same module or in different modules, are they in the same order or in different order, etc ...?

Peter

Great! I hacked your quick hack and it works great for me. Much appreciated.